package com.feishu.core.service.factory.impl;


import com.feishu.base.dto.HttpClientTokenDTO;
import com.feishu.base.service.ConstructionHttpClientService;
import com.feishu.base.type.ConstructionInterfaceType;
import com.feishu.service.FeiShuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@ConstructionInterfaceType(defaultValue = "feishuProject")
public class FeiShuConstructionHttpClientServiceImpl implements ConstructionHttpClientService {
    private static HttpClientTokenDTO httpClientTokenDTO;

    @Autowired
    FeiShuService feiShuService;


    @Override
    public Map<String, Object> getInSettingMap(String code,String name) {
        List<Map<String, Object>> inSettingList=feiShuService.getInTreeMap(code, name);
        Map<String,Object> settingMap=new HashMap<>();
        for(int i=0;i<inSettingList.size();i++){
            String plm_source_type_id= (String) inSettingList.get(i).get("plm_source_type_id");
            if(settingMap.containsKey(plm_source_type_id)){
                List<Map<String, Object>> settingList= (List<Map<String, Object>>) settingMap.get(plm_source_type_id);
                settingList.add(inSettingList.get(i));
                settingMap.put(plm_source_type_id,settingList);
            }
            else{
                List<Map<String, Object>> settingList=new ArrayList<>();
                settingList.add(inSettingList.get(i));
                settingMap.put(plm_source_type_id,settingList);
            }
        }
        return settingMap;
    }

    @Override
    public List<Map<String, Object>> getOutSettingList(String code,String name) {
        return feiShuService.getOutTreeMap(code, name);
    }


    @Override
    public HttpClientTokenDTO getHttpClientTokenDTO() {
        return httpClientTokenDTO;
    }

    @Override
    public void setHttpClientTokenDTO(HttpClientTokenDTO httpClientTokenDTO) {
        this.httpClientTokenDTO=httpClientTokenDTO;
    }

    @Override
    public List<Map<String, Object>> getOptions(String code,String name) {
        return feiShuService.getOptions(code, name);
    }
}
